package com.facemox.task;

import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;
import com.facemox.bean.User;
import com.facemox.service.UserService;
import com.facemox.util.JsonData;

/**
 * 0、定时任务步骤：
 * 1、在启动类里面添加@EnableScheduling注解
 * 2、编写一个定时任务的类，添加@component注解
 * 3、方法上添加@Scheduled注解，并设置固定速率fixedRate
 */
@Component
@RestController
public class TestTask {
    
    @Autowired
    private UserService userService;
    
    //@Scheduled(fixedRate=5000000)
    public JsonData addUserTask() {
        User user = new User();
        user.setUserId(20);
        user.setUsername("15210232015");
        user.setCreateTime(new Date());
        int id = userService.add(user);
        System.out.println("插入成功:"+id);
        return new JsonData("101", "插入成功", "ID:"+id);
    }
}
